

function setPagination(count,topId,downId,topDet,botDet)
{
	
	var perPage = pagination['resultsPerPage'];
	//alert(parseInt(count)+'------'+parseInt(perPage));
	if( parseInt(count) > 0 && parseInt(count) > parseInt(perPage) ){
		
		if(topId!=''){
			$('#'+topId).html(pagination['pager']);
		}
		if(downId!=''){
			$('#'+downId).html(pagination['pager']);
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
	else   {
		if(topId!=''){
			$('#'+topId).html('');
		}
		if(downId!=''){
			$('#'+downId).html('');
		}
		if(topDet!=''){
			$('#'+topDet).html(pagination['resultsDetails']);
		}
		if(botDet!=''){
			$('#'+botDet).html(pagination['resultsDetails']);
		}
	}
}
function ajaxPager(page)
{
	var perPage = pagination['resultsPerPage'];
	//Eg: var url = '/article/prediction/pagerlist/${article/id}/' + page + '/' + perPage; 
	var url = requestUrl + page +  '/' + perPage;
	reg = /\s+/;
	url = url.replace(reg,'-');
	//Eg :  var Params='category=' + $('#prediction_type').val();
	$.getJSON(url,Params, function(data) {
		  $('#listContent').html(data.output);
	      pagination['pages'] = data.pages;
	      pagination['pager'] = data.pager;
	      pagination['currentPage'] = data.currentPage;
		  pagination['resultsDetails'] = data.resultsDetails;
		  setPagination(data.resultsCount,'topPagerId','downPagerId',"topdet","botdet"); 
		} );
	 	
}


function sortingBy(contenttype,bid,pagesize,page,field,order,actionname,urlp)
{
	var fieldorder='ASC',urlPath; 
	if(actionname ==  undefined )
		urlPath = urlp+"index/";
	else
		urlPath = urlp+actionname+"";
	$.ajax({
	type: "POST",
	url: urlPath,
	data: "id="+bid+"&page="+page+"&pagesize="+pagesize+"&field="+field+"&fieldorder="+order,
	success: function(msg){
		$('#postedComments').html(msg);
	}
	});
}



function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function limitText(limitField, limitNum,textMsg) {
    if (limitField.value.length > limitNum) {
		$('#'+textMsg).html('Text too long. Must be '+limitNum+' characters or less');
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
		$('#'+textMsg).html('');
	}
}
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function trimComma(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,",");
}
function validInput(string)
{
re=/[<>]/;
return re.test(string);
}

function checkURL(value) { 
  var urlregex = new RegExp(
        "^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
  if(urlregex.test(value))
  {
    return(true);
  }
  return(true);
 
}

function isValidEmailAddress(emailAddress)
{
       var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
       return pattern.test(emailAddress);
}

function getObserver()
{
		if(observer == true)
		{
			alert('Functionality of this site is not accessible for your login.');	
			return false;
		} else {
			return true;	
		}
}


function imposeMaxLength(Object, MaxLen)
{
	
	if (Object.value.length > MaxLen) {
		Object.value = Object.value.substring(0, MaxLen);
	} 
}

  /*
 	Eg: SelectDropDown("value",document.addEmployement.fromMonth -- Element Name); 
 */
 function SelectDropDown(selectItem,listBox) {

  var intIndex = 0;
  var SelectList = listBox;
  for( intIndex = 0; intIndex < SelectList.options.length; intIndex++ ) {
	 
		if( SelectList.options[intIndex].value == selectItem ) {
			SelectList.selectedIndex = intIndex;
			break;
		}
  }    
}

///function to change the village
function changeVillage(villageId)
{
	window.location.href = '/user/myhome/change-village/'+villageId;
}


function formatDate() {
	d = new Date();
	
	var ap = "am";
	var hr = d.getHours();
	var mi=d.getMinutes();
	//var day=d.getDay();
   if (hr  > 11) { ap = "pm";             }
   if (hr  > 12) { hr  = hr - 12;      }
   if (hr    == 0) { hr  = 12;             }
   if (hr    < 10) { hr    = "" + hr ;   }
   if ( mi < 10) {  mi = "0" +  mi; }
   
	
	$('#header_date').append("<div>" + 
			['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][d.getDay()] + ', ' +  
			['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()] +
			' ' + d.getDate() +' &nbsp;'+hr + ':' + mi + ap +'</div>');
			
}
//Rajendra
function isValidZip(zipcode){
	var re = /^[A-Za-z0-9]+$/;
    return re.test(zipcode);
}